package logic

import (
	"context"
	"usershop/user_srv/internal/svc"
	"usershop/user_srv/model/mysql"
	"usershop/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserInfoByUsernameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserInfoByUsernameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoByUsernameLogic {
	return &GetUserInfoByUsernameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserInfoByUsernameLogic) GetUserInfoByUsername(in *user.GetUserInfoByUsernameRequest) (*user.GetUserInfoResponse, error) {
	// todo: 获取用户信息By用户名

	u := mysql.User{}
	err := u.GetUsernameInfo(in.Username)
	if err != nil {
		logx.Error("获取用户信息失败：", err)
		return nil, err
	}

	return &user.GetUserInfoResponse{
		UserId:   int64(u.ID),
		Username: u.Username,
		Mobile:   u.Mobile,
		Password: u.Password,
		Salt:     u.Sale,
	}, nil
}
